﻿/// <reference name="MicrosoftAjax.js" />
/// <reference path="file://C:/Program Files/Common Files/Microsoft Shared/Web Server Extensions/14/TEMPLATE/LAYOUTS/SP.core.debug.js" />
/// <reference path="file://C:/Program Files/Common Files/Microsoft Shared/Web Server Extensions/14/TEMPLATE/LAYOUTS/SP.debug.js" />
/// <reference path="file://C:/Program Files/Common Files/Microsoft Shared/Web Server Extensions/14/TEMPLATE/LAYOUTS/SP.Ribbon.debug.js" />

function ULS_SP() {
	if (ULS_SP.caller) {
		ULS_SP.caller.ULSTeamName = 'Windows SharePoint Services 4';
		ULS_SP.caller.ULSFileName = 'SlamCms.PublishingPageComponent.js';
	}
}

Type.registerNamespace('SlamCms.Publishing.UI');
SlamCms.Publishing.UI.PublishingPageComponent = function () {
	ULS_SP();
	SlamCms.Publishing.UI.PublishingPageComponent.initializeBase(this);
}

SlamCms.Publishing.UI.PublishingPageComponent.initialize = function () {
	ULS_SP();
	var ribbonPageManager = SP.Ribbon.PageManager.get_instance();
	if (null !== ribbonPageManager) {
		ribbonPageManager.addPageComponent(this.instance);
		ribbonPageManager.get_focusManager().requestFocusForComponent(this.instance);
	}
	//ExecuteOrDelayUntilScriptLoaded(Function.createDelegate(null, SlamCms.Publishing.UI.PublishingPageComponent.initializePageComponent), 'SP.Ribbon.debug.js');
}

SlamCms.Publishing.UI.PublishingPageComponent.refreshRibbonStatus = function () {
	SP.Ribbon.PageManager.get_instance().get_commandDispatcher().executeCommand(Commands.CommandIds.ApplicationStateChanged, null);
}

SlamCms.Publishing.UI.PublishingPageComponent.prototype = {
	init: function () { },
	getId: function () {
		return 'PublishingPageComponent';
	},
	getFocusedCommands: function () {
		ULS_SP();
		return [];
	},
	getGlobalCommands: function () {
		ULS_SP();
		return ['EditFormPublishingDeleteButton', 'EditFormPublishingPublishButton', 'EditFormPublishingSubmitForApprovalButton'];
	},
	isFocusable: function () {
		ULS_SP();
		return true;
	},
	receiveFocus: function () {
		ULS_SP();
		return true;
	},
	yieldFocus: function () {
		ULS_SP();
		return true;
	},
	canHandleCommand: function (commandId) {
		ULS_SP();
		switch (commandId) {
			case 'EditFormPublishingDeleteButton':
			case 'EditFormPublishingPublishButton':
			case 'EditFormPublishingSubmitForApprovalButton':
				return true;
			default: return false;
		}

	},
	handleCommand: function (commandId, properties, sequence) {
		ULS_SP();
		var element = null;
		if (commandId === 'EditFormPublishingPublishButton') {
			if (document.getElementById('slamCmsPublishingPublishButtonId') != null) {
				element = document.getElementById(document.getElementById('slamCmsPublishingPublishButtonId').value);
			}
		} else if (commandId == 'EditFormPublishingSubmitForApprovalButton') {
			if (document.getElementById('slamCmsPublishingSubmitForApprovalButtonId') != null) {
				element = document.getElementById(document.getElementById('slamCmsPublishingSubmitForApprovalButtonId').value);
			}
		} else if (commandId == 'EditFormPublishingDeleteButton') {
			if (document.getElementById('SlamCmsPublishingDeleteButtonId') != null) {
				element = document.getElementById(document.getElementById('slamCmsPublishingDeleteButtonId').value).childNodes[0];
			}
		}
		if (element != null) {
			if (Sys.Browser.agent === Sys.Browser.InternetExplorer) {
				element.click();
			}
			else {
				SP.Ribbon.NativeUtility.ffClick(element);
			}
			return true;
		} else {
			return false;
		}
	}
}

SlamCms.Publishing.UI.PublishingPageComponent.registerClass('SlamCms.Publishing.UI.PublishingPageComponent', CUI.Page.PageComponent);
SlamCms.Publishing.UI.PublishingPageComponent.instance = new SlamCms.Publishing.UI.PublishingPageComponent();
SlamCms.Publishing.UI.PublishingPageComponent.initialize();

SP.SOD.notifyScriptLoadedAndExecuteWaitingJobs('SlamCms.PublishingPageComponent.js');